package datastructure.graph;

/**
 * @author jack.wu
 * @version 1.0
 * @date 2020-04-30
 */
public class SearchGraph {
    public static void main(String[] args) {
        int[][] vertix = {{1, 2, 3, 100, 200},
                {4, 17, 22, 33, 142},
                {6, 9, 88, 133, 177, 199}};
        boolean flag = search(vertix, 199);
        System.out.println(flag);
    }

    public static boolean search(int[][] vertix, int target) {
        for (int[] row : vertix) {
            if (binarySearch(row, target)) {
                return true;
            }
        }
        return false;
    }

    private static boolean binarySearch(int[] row, int target) {
        int left = 0;
        int right = row.length - 1;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (row[mid] < target) {
                left = mid + 1;
            } else if (row[mid] > target) {
                right = mid - 1;
            } else {
                return true;
            }
        }
        return false;
    }

}
